package LeetCode.stack_queue;

import java.util.Stack;

public class LC_155 {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;
    public LC_155() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }
    public void push(int val){
        stack.push(val);
        if(minStack.empty() || val <= minStack.peek()) {
            minStack.push(val);
        }
    }
    public void pop(){
        if(!stack.empty()){
            Integer data = stack.pop();
            if(data.equals(minStack.peek())){
                minStack.pop();
            }
        }
    }
    public int top(){
        if(!stack.empty()) {
            return stack.peek();
        }
        return -1;
    }
    public int getMin(){
        return stack.pop();
    }
}
